<?php

namespace Beerus\Modules\VirtualPhone\Actions;

use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;
use Doraemon\model\VirtualPhone\DesignerVirtualPhoneRecord;
use Doraemon\tools\AlibabaCloud\VirtualPhone;
use Doraemon\service\BusinessUser\EncryptPhone;
use hhz\constant\basic\UserExtendPhoneScene;

class ShowRealPhone extends RowAction
{
    public $name = '查看真实手机号码';

    public function handle($id)
    {
        return $this->response()->success('查看成功')->refresh();
    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }
        return $key;
    }

    public function form($request)
    {
        $id = $request->id;
        //获取用户的真实手机号
        $condition = [
            "id" => $id,
        ];
        $virtualPhoneInfo = DesignerVirtualPhoneRecord::getByCondition($condition);
        $userPhone = EncryptPhone::getDecryptPhoneInfo($virtualPhoneInfo['encrypt_user_id'],UserExtendPhoneScene::DESIGNER_VIRTUAL_PHONE);
        $this->text('realPhone', '用户真实手机号')->default($userPhone);;
    }
}
